//
// Created by buyongjiu on 2024/4/22.
//

#ifndef FEI_PARSER_GRAMMAR_H
#define FEI_PARSER_GRAMMAR_H

#include <string>
#include <map>
#include <vector>
#include <unordered_map>
#include <set>

enum Type {VT, VN, DOT, END};

struct V {
    Type type;
    std::string name;
    V(Type type, std::string name) {
        this->type = type;
        this->name = name;
    }
};

class Grammar {
public:
    std::map<V *, std::vector<std::vector<V *>>> productions;
    int Scan_CFG_Grammer(std::vector<std::string> corresponding_input);
    std::map<std::string, V *> V_map;
    std::set<V *> V_set;
    std::map<std::string, std::vector<V *>> First;
    std::string start;
    void EliminateLeftRecursion();
    void EliminateindirectLeftRecursion();
    void EliminatedirectLeftRecursion();
    void ExtendGrammar();
    void get_First();
    void get_First_Helper(V *v);
};


#endif //FEI_PARSER_GRAMMAR_H
